////////////////////////////////////////////////////////////////////////////////
/// Midnight Circus 2007
////////////////////////////////////////////////////////////////////////////////

namespace GatherTogether
{
    /// <summary>
    /// The base class of exceptions that will be thrown by the merger when
    /// it encounters errors.
    /// </summary>
    class MergerException : System.ApplicationException
    {
        public MergerException(string message)
            : base(message)
        {
        }
    }

    class Merger
    {
        public static void Merge(GatherDB masterDB, GatherDB otherDB)
        {
            MergeGatherItems(masterDB.Items, otherDB.Items);
            MergeGatherDrops(masterDB.Drops, otherDB.Drops);
            MergeGatherDropRates(masterDB.DropRates, otherDB.DropRates);
        }

        public static void MergeGatherItems(GatherItems.GatherItemsDB masterItemsDB, GatherItems.GatherItemsDB otherItemsDB)
        {
            masterItemsDB.Merge(otherItemsDB);
        }       

        public static void MergeGatherDrops(GatherDrops.GatherDropsDB masterDropsDB, GatherDrops.GatherDropsDB otherDropsDB)
        {
            foreach (GatherDrops.Node otherNode in otherDropsDB)
            {
                masterDropsDB.AddNode(otherNode);
            }
        }

        public static void MergeGatherDropRates(GatherDropRates.GatherDropRatesDB masterDropRatesDB, GatherDropRates.GatherDropRatesDB otherDropRatesDB)
        {
            masterDropRatesDB.Merge(otherDropRatesDB);
        }
    }
}
